<script>
import { mapState } from 'vuex'
import SearchManage from '@/components/basic/SearchManage.vue'
import { formConfig, column } from './formConfig.js'
import { config2 } from '../Plan/formConfig.js'
export default {
    extends: SearchManage,
    data() {
        return {
            table_title: '巡检记录',
            url: 'point/record',
            formConfig: null,
            tableColumn: null,
            queryForm: {
                page: 1,
                size: 20,
                scope_id: null,
                device_name: '',
                start_time: null,
                end_time: null,
                type_id: null,
                reporter: '',
                scope_id_list: [],
                device_id: null,
                record_state: null,
                result: null,
                plan_id: null,
                id: null,
            },
            queryFormC: {
                page: 1,
                size: 20,
                scope_id: null,
                device_name: '',
                start_time: null,
                end_time: null,
                type_id: null,
                reporter: '',
                scope_id_list: [],
                device_id: null,
                record_state: null,
                result: null,
                plan_id: null,
                id: null,
            },
        }
    },
    methods: {
        toPlan(val) {
            this.$router.push({
                name: 'point_plan',
                params: {
                    id: val.plan_id,
                },
            })
        },
    },
    computed: {
        ...mapState('backstage', ['backstageData', 'deviceType']),
        operate() {
            return parseInt(sessionStorage.getItem('operate')) === 1
        },
        tags() {
            if (this.pagination.total !== undefined) {
                return [{ title: '总数', num: this.pagination.total }, null, { title: '未检', num: this.stat.unchecked }, { title: '已检', num: this.stat.checked }]
            } else return []
        },
    },
    created() {
        if (this.$route.params.plan_id !== undefined) {
            this.queryForm.plan_id = this.$route.params.plan_id
        }
        if (this.$route.params.device_id !== undefined) {
            this.queryForm.device_id = this.$route.params.device_id
        }
        this.searchBtn()
        formConfig[0].options = this.backstageData
        this.formConfig = formConfig
        this.dialog.config = config2.slice(1, config2.length)
        column[column.length - 1].buttons = [
            {
                text: '查看计划',
                click: (val) => this.toPlan(val),
                icon: 'el-icon-s-comment',
            },
            {
                text: '编辑',
                click: (val) => this.handleEdit(val),
                if: () => this.operate,
                icon: 'el-icon-edit',
            },
            {
                text: '删除',
                click: (val) => this.delete(val),
                if: () => this.operate,
                icon: 'el-icon-delete',
            },
        ]
        this.tableColumn = column
    },
}
</script>
